<?php namespace app\admin\controller;

class Tag extends Common{
    //标签展示
    public function index(){
    //此处书写代码...
        $tags=(new \system\model\Tag())->index();
         View::with('tags',$tags);
        return view();
    }
    //标签添加
    public  function tagadd(){
        if(IS_POST){
            $res=(new \system\model\Tag())->tagadd();
            if($res){
             message('添加成功','index','success');
            }else{
                message('添加失败','index','error');
            }
        }
        return view();
    }
    //标签修改
    public function tagedit(){
        if(!isset($_GET['tid'])){
            header('location:index.php?s=admin/tag/index');
        }
        $tid=$_GET['tid'];
        //旧数据
        $oldtname=Db::table('tag')->where('tid',$tid)->first();
//        p($oldtname);
        View::with('oldtname',$oldtname);
//        修改动作
        if(IS_POST){
            $res=(new \system\model\Tag())->tagedit();
            if($res){
                message('修改成功','index','success');
            }else{
                message('修改失败','index','error');
            }
        }
        return view();
    }
    /**
     * 删除标签
     */
    public  function tagdel(){
        if(!isset($_GET['tid'])){
            header('location:index.php?s=admin/tag/index');
        }
        $tid=$_GET['tid'];
        $res=Db::table('tag')->delete($tid);
        if($res){
            message('删除成功','index','success');
        }else{
            message('删除失败','index','error');
        }
    }

}
